<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>风险管理和隐患排查治理工具箱</title>
    <script src="./layui/layui.js"></script>
    <script src="./jquery-3.6.0.min.js"></script>
    <script src="./common.js"></script>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <link rel="stylesheet" href="./css/font-awesome.min.css">
    <link rel="stylesheet" href="./css/style.css">
</head>

<body>
    <header class="index_header">
        <ul>
            <li>
                <img src="./images/logo.png" alt="logo">
                <h3>风险管理和隐患排查治理工具箱</h3>
            </li>
            <li>
                <b>Version: 1.0.0</b>
            </li>
        </ul>
    </header>
    <div class="index_nav">
        <a class="back_btn" href="javascript:;" onclick="backPage()">
            <i class="fa fa-arrow-circle-left" style="font-size: 2rem;margin-top: .5rem;color: #4bd0d0;"></i>
        </a>
        <a class="back_btn" href="javascript:;" onclick="location.reload()">
            <i class="fa fa-refresh" style="font-size: 2rem;margin-top: .5rem;color: #4bd0d0;"></i>
        </a>
    </div>
    <div class="index_menu">
        <ul>
            <a href="./analysis.html">
                <li>
                    <div class="index_menu_item" style="background: #C4004F;">
                        <i class="fa fa-search"></i>
                    </div>
                    <p>分析匹配工具</p>
                </li>
            </a>
            <a href="javascript:;" onclick="openTools()">
                <li>
                    <div class="index_menu_item" style="background: #0067C4;">
                        <i class="fa fa-folder"></i>
                    </div>
                    <p>手动选择工具</p>
                </li>
            </a>
        </ul>
    </div>
</body>
</html>

<script>
// function openForm() {
//     console.log('打开表单')
// }

const { ipcRenderer } = require('electron')

var fn = true;
//监听main process里发出的message
//监听main process里发出的message
ipcRenderer.on('downstate', (event, arg) => {
    console.log("下载状态：" + arg);
    if (arg == 'start') {
        if (fn) {
            loading()
            fn = false
        }
    }else if (arg == 'completed') {
        layer.close(loadingBox)
        fn = true
        alert('文件下载完成!')
    }else if (arg == 'cancel') {
        fn = true
        layer.close(loadingBox)
    }else{
        fn = true
        layer.close(loadingBox)
        alert('桌面已存在该文件,无法覆盖!')
    }
})

function backPage() {
    ipcRenderer.send("backPage", 'login');
}

function downloadExcel(tabelName) {
    ipcRenderer.send("downloadExcel", tabelName);
}


function openTools() {
    var html = '<div class="table_list" style="margin-top: 2rem;">\
        <ul>\
            <a href="javascript:;" onclick=downloadExcel("JSA")><li>\
                <div style="background: #C40000;">JSA</div>\
                <p>工作安全分析</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("JCC")><li>\
                <div style="background: #F39400;">JCC</div>\
                <p>任务周期性评估</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("MOC")><li>\
                <div style="background: #CFDF00;">MOC</div>\
                <p>变更管理</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("COD")><li>\
                <div style="background: #76C400;">COD</div>\
                <p>设计变更</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("PSSR")><li>\
                <div style="background: #00C46C;">PSSR</div>\
                <p>启动前安全评估</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("TRA")><li>\
                <div style="background: #009EC4;">TRA</div>\
                <p>任务风险评估</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("FISH")><li>\
                <div style="background: #005EC4;">FISH</div>\
                <p>因果分析法</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("FTA")><li>\
                <div style="background: #9F00C4;">FTA</div>\
                <p>事故树分析法</p>\
            </li></a>\
            <a href="javascript:;" onclick=downloadExcel("SCA")><li>\
                <div style="background: #C40073;">SCA</div>\
                <p>安全检查表</p>\
            </li></a>\
        </ul>\
    <div>'
    layer.open({
        type: 1,
        skin: 'layui-layer-tools', //样式类名
        title: '选择工具',
        closeBtn: 0, //不显示关闭按钮
        anim: 2,
        shadeClose: true, //开启遮罩关闭
        area: ['100%', '400px'],
        content: html
    });
}
</script>